<template>
  <header class="header">
    <div class="header_center">
      <a href="/" title="技考邦首页">
        <h1 class="header_center_h1">
          <img src="https://static.dzyxzx.cn/jkbpc/logo.jpg" style="width: 125px;height: 30px;" />
        </h1>
      </a>
      <div class="header_center_search">
        <el-select class="header_center_search_select" clearable v-model="searchTypeValue" placeholder="请选择"
          size="small">
          <el-option v-for="item in searchOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <el-input class="header_center_search_input" type="text" v-model="searchInputValue"
          placeholder="请输入课程名称关键字"></el-input>
        <button class="header_center_search_btn">搜索</button>
      </div>
      <el-dropdown>
        <div class="header_center_user">
          <span class="header_center_user_name">{{ title || '未知机构' }}</span>
          <el-image class="header_center_user_avatar" :src="profilesPic || 'https://static.dzyxzx.cn/jkbpc/user.png'" fit="fill"
            :alt="title"></el-image>
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>
              <a href="/">官网首页</a>
            </el-dropdown-item>
            <el-dropdown-item>
              <a href="/userCenter">个人中心</a>
            </el-dropdown-item>
            <el-dropdown-item>
              <a href="/setPassword">修改密码</a>
            </el-dropdown-item>
            <el-dropdown-item @click="loginOut">
              <a>退出登录</a>
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </header>
  <div class="main">
    <div class="main_center">
      <div class="main_center_left">
        <AdminMenu :list="menuData" :currentHref="menuActive"></AdminMenu>
      </div>
      <div class="main_center_right">
        <slot />
      </div>
    </div>
  </div>
  <footer class="footer">
    <div class="footer_center">
      <div class="footer_center_info">
        <div class="footer_center_info_title">技考邦</div>
        <div class="footer_center_info_desc">
          技考邦在线技考学习平台为达州市元翔教育管理有限责任公司打造，深耕国内特种作业教培领域。技考邦致力安全生产和特种作业在线教育领域，成为越来越多的培训机构首选网络教学平台解决方案。
        </div>
      </div>
      <div class="footer_center_list">
        <ul class="footer_center_list_ul">
          <li class="footer_center_list_ul_li" style="margin-right: 100px">
            <div class="footer_center_list_ul_li_title">条款与声明</div>
            <a class="footer_center_list_ul_li_link" href="/website_statement" title="网站声明">网站声明</a>
            <a class="footer_center_list_ul_li_link" href="/privacy_policy" title="隐私政策">隐私政策</a>
            <a class="footer_center_list_ul_li_link" href="/user_agreement" title="用户协议">用户协议</a>
          </li>
          <li class="footer_center_list_ul_li" style="margin-right: 101px">
            <div class="footer_center_list_ul_li_title">服务内容</div>
            <a class="footer_center_list_ul_li_link" href="/curriculum" title="课程中心">课程中心</a>
            <a class="footer_center_list_ul_li_link" href="/exercises" title="题库中心">题库中心</a>
            <a class="footer_center_list_ul_li_link" href="/mechanism" title="机构入驻">机构入驻</a>
          </li>
          <li class="footer_center_list_ul_li">
            <div class="footer_center_list_ul_li_title">联系我们</div>
            <div class="footer_center_list_ul_li_link flex">
              <img class="icon" src="https://static.dzyxzx.cn/jkbpc/footer-phone.png" />
              <span class="span">客服热线：0818-2282222</span>
            </div>
            <a class="footer_center_list_ul_li_link flex" href="/" title="技考邦">
              <img class="icon" src="https://static.dzyxzx.cn/jkbpc/footer-web.png" />
              <span class="span">网址：www.jkb100.com</span>
            </a>
            <div class="footer_center_list_ul_li_link flex">
              <img class="icon" src="https://static.dzyxzx.cn/jkbpc/footer-address.png" />
              <span class="span">地址：四川省达州市通川区金龙大道139号</span>
            </div>
          </li>
        </ul>
      </div>
    </div>
    <div class="footer_copyright">
      <span>版权所有：Copyright @copy; 2024 技考邦, All Rights
        Reserved&nbsp;&nbsp;&nbsp;备案号：</span>
      <a class="footer_copyright_link" href="https://beian.miit.gov.cn/"
        target="_blank">蜀ICP备2024084661号-1</a>
    </div>
  </footer>
</template>

<script setup>
import { loginOutApi, getCurrentAdminAuth } from '~/server/api'
// import { useToken } from '~/store/token'
import { useToken, useUserinfo, useRecord100 } from '~/store'
const { delToken } = useToken()
const { delUserinfo } = useUserinfo()
const { record100 } = useRecord100()
defineProps({
  menuActive: {
    type: String,
    default: '',
  },
});
const searchOptions = ref([{
  value: '',
  label: "请选择",
}, {
  value: 1,
  label: "课程",
}]);
const searchTypeValue = ref("");
const searchInputValue = ref("");
const title = useRoute().meta.mechanism ? useRoute().meta.mechanism.shortName : ref('未知机构');
const profilesPic = useRoute().meta.userinfo ? useRoute().meta.userinfo.profilesPic : null;
const menuData = useRoute().meta.adminMenuData || [];
// 退出机构端
const loginOut = () => {
  ElMessageBox.confirm('是否退出登录？', {
    showClose: false,
    closeOnClickModal: false,
    closeOnPressEscape: false
  }).then(() => {
    useServerRequest(loginOutApi, {
      method: 'get'
    }).then(({ errno, errmsg }) => {
      if (errno === 0) {
        localStorage.clear()
        useToken().token = '';
        // delToken()
        delUserinfo()
        window.location.href = '/login';
        return false
      }
    }).catch(err => {
      ElMessage.error('退出失败')
    })
  }).catch(() => { })
}
onMounted(() => {
  if (record100) {
    useToken().token = '';
    // delToken()
    delUserinfo()
  }
})
</script>

<style lang="less" scoped>
.header {
  background-color: #fff;

  &_center {
    width: 1200px;
    height: 65px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;

    &_h1 {
      height: 30px;
      line-height: 30px;
      margin: 0;
    }

    &_search {
      width: 545px;
      height: 38px;
      background: #ffffff;
      border-radius: 5px;
      border: 1px solid #ff3f29;
      display: flex;
      align-items: center;

      &_select {
        width: 71px;
        padding: 0;
      }

      &_input {
        font-size: 14px;
        flex: 1;
        overflow: hidden;
      }

      &_btn {
        width: 47px;
        height: 38px;
        line-height: 36px;
        text-align: center;
        background: #ff3f29;
        font-size: 14px;
        color: #ffffff;
        outline: none;
        border: 0;
        cursor: pointer;
        border-radius: 0 5px 5px 0;
      }
    }

    &_user {
      display: flex;
      align-items: center;

      &_name {
        font-size: 14px;
        margin-right: 10px;
        color: #000;
      }

      &_avatar {
        width: 36px;
        height: 36px;
        border-radius: 36px;
        overflow: hidden;
      }
    }
  }
}

.main {
  background-color: #f9f9f9;
  padding: 20px 0;
  min-height: calc(100vh - 375px);

  &_center {
    display: flex;
    // width: 1400px;
    padding: 0 20px;
    margin: 0 auto;
    align-items: flex-start;

    &_left {
      margin-right: 20px;
    }

    &_right {
      flex: 1 0;
      overflow: hidden;
    }
  }
}

.footer {
  background: #1f2833;

  &_center {
    width: 1200px;
    height: 230px;
    margin: 0 auto;
    display: flex;

    &_info {
      padding-top: 42px;
      width: 384px;

      &_title {
        font-weight: bold;
        font-size: 26px;
        color: #5f646e;
      }

      &_desc {
        font-size: 14px;
        color: #5f646e;
        line-height: 24px;
        margin-top: 28px;
        text-indent: 30px;
      }
    }

    &_list {
      flex: 1;
      margin-left: 133px;
      overflow: hidden;

      &_ul {
        display: flex;
        // justify-content: space-between;

        &_li {
          padding-top: 43px;

          &_title {
            font-weight: bold;
            font-size: 20px;
            color: #5f646e;
            margin-bottom: 30px;
          }

          &_link {
            display: block;
            font-size: 14px;
            margin-top: 18px;
            color: #5f646e;

            &.flex {
              display: flex;
              align-items: flex-start;

              .icon {
                margin-right: 10px;
                width: 17px;
                height: 17px;
              }

              .span {
                font-size: 14px;
                color: #5f646e;
                line-height: auto;
              }
            }
          }
        }
      }
    }
  }

  &_copyright {
    height: 80px;
    border-top: 1px solid #2d3241;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #5f646e;

    span {
      color: #5f646e;
    }

    &_link {
      color: #5f646e;
    }
  }
}
</style>
<style lang="less">
.header_center_search {

  .el-select__wrapper,
  .el-input__wrapper {
    box-shadow: none !important;
  }

  .el-select__wrapper {
    padding-left: 12px;
    padding-right: 0;
  }
}
</style>
